#include<stdio.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>


int main()
{
    pid_t id=fork();
    if(id==0)
    {
        //子进程
        int cnt = 3;
        while(cnt)
        {
            cnt--;
            printf("我是子进程，我的pid:%d\n",getpid());
            sleep(1);
        }
        exit(10);
    }
    //wait获取子进程信息
    int status=0;
    pid_t rid=waitpid(id,&status,0);
    if(rid>0)
    {
        printf("获取成功\n");
        if(WIFEXITED(status))
        {
            printf("正常运行结束：%d\n",WEXITSTATUS(status));
        }
        else{

            printf("进程异常");
        }
    }
    return 0;
}
